package com.vint.openjudge;

import java.util.Scanner;

/**
 * 1. medium
 * 2. 滑雪，找出最长路径
 * 3.http://bailian.openjudge.cn/practice/1088/
 */
public class Openjudeg1088 {
	public static void main(String args[]) throws Exception
	{
		Scanner cin=new Scanner(System.in);
		String line = cin.nextLine();
		String[] base = line.split(" ");
		n = Integer.parseInt(base[0]);
		m = Integer.parseInt(base[1]);
		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				map[i][j] = cin.nextInt();
				dp[i][j] = 0;
			}
		}
		int ans = 0;
		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				ans = Math.max(ans,dp(i,j));
			}
		}
		System.out.println(ans);
	}

	public static int[][] dp = new int[110][110];
	public static int[][] map = new int[110][110];
	public static int[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};
	public static int m;
	public static int n;

	public static int dp(int x ,int y){
		if(dp[x][y]!=0){
			return dp[x][y];
		}
		int cnt = 0;
		for(int i=0; i<4; i++){
			int xx = x + dir[i][0];
			int yy = y + dir[i][1];
			if(xx<0||xx>=n||yy<0||yy>=m)continue;
			if(map[xx][yy]<map[x][y]){
			    cnt = Math.max(cnt,dp(xx,yy));
			}
		}
		dp[x][y] = cnt + 1;
		return dp[x][y];
	}
}
